<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const isLogin = ref(true)
const loginForm = ref({
  username: '',
  password: ''
})
const registerForm = ref({
  username: '',
  password: '',
  confirmPassword: ''
})

const handleLogin = () => {
  // 登录逻辑待实现
  console.log('登录表单：', loginForm.value)
}

const handleRegister = () => {
  // 注册逻辑待实现
  console.log('注册表单：', registerForm.value)
}

const switchMode = () => {
  isLogin.value = !isLogin.value
}
</script>

<template>
  <div class="login-container">
    <h1 class="system-title">教材管理系统</h1>
    <div class="login-box">
      <div class="form-container">
        <h2>{{ isLogin ? '欢迎回来' : '创建账号' }}</h2>
        <p class="subtitle">{{ isLogin ? '请登录您的账号' : '填写信息以创建新账号' }}</p>
        <!-- 登录表单 -->
        <el-form v-if="isLogin" :model="loginForm" label-position="top">
          <el-form-item label="用户名">
            <el-input 
              v-model="loginForm.username" 
              placeholder="请输入用户名"
              :prefix-icon="'User'"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input 
              v-model="loginForm.password" 
              type="password" 
              placeholder="请输入密码"
              :prefix-icon="'Lock'"
              show-password
            ></el-input>
          </el-form-item>
          <div class="form-footer">
            <el-button type="primary" class="submit-btn" @click="handleLogin">登录</el-button>
            <p class="switch-text">
              还没有账号？
              <el-button link type="primary" @click="switchMode">立即注册</el-button>
            </p>
          </div>
        </el-form>
        <!-- 注册表单 -->
        <el-form v-else :model="registerForm" label-position="top">
          <el-form-item label="用户名">
            <el-input 
              v-model="registerForm.username" 
              placeholder="请输入用户名"
              :prefix-icon="'User'"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input 
              v-model="registerForm.password" 
              type="password" 
              placeholder="请输入密码"
              :prefix-icon="'Lock'"
              show-password
            ></el-input>
          </el-form-item>
          <el-form-item label="确认密码">
            <el-input 
              v-model="registerForm.confirmPassword" 
              type="password" 
              placeholder="请确认密码"
              :prefix-icon="'Lock'"
              show-password
            ></el-input>
          </el-form-item>
          <div class="form-footer">
            <el-button type="primary" class="submit-btn" @click="handleRegister">注册</el-button>
            <p class="switch-text">
              已有账号？
              <el-button link type="primary" @click="switchMode">立即登录</el-button>
            </p>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<style scoped>
.login-container {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(120deg, #e0f2fe 0%, #409EFF 100%);
}

.system-title {
  font-size: 42px;
  font-weight: 600;
  color: #fff;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3), 0 0 30px rgba(64, 158, 255, 0.5);
  margin-bottom: 40px;
  letter-spacing: 2px;
}

.login-box {
  width: 662px;
  height: 672px;
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.form-container {
  width: 400px;
  padding: 30px;
}

h2 {
  margin-bottom: 12px;
  color: #303133;
  font-size: 32px;
  text-align: center;
  font-weight: 600;
}

.subtitle {
  color: #909399;
  text-align: center;
  margin-bottom: 35px;
  font-size: 16px;
}

.el-form-item {
  margin-bottom: 24px;
}

.form-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin-top: 35px;
}

.submit-btn {
  width: 100%;
  height: 48px;
  font-size: 18px;
}

.switch-text {
  color: #909399;
  font-size: 15px;
}

:deep(.el-input__wrapper) {
  padding: 2px 16px;
}

:deep(.el-input__inner) {
  height: 46px;
  font-size: 15px;
}

:deep(.el-form-item__label) {
  padding-bottom: 10px;
  font-size: 16px;
  color: #606266;
}

:deep(.el-button--link) {
  font-size: 15px;
  font-weight: 500;
}
</style>